package ifi.p17.view;

import ifi.p17.controler.Control;
import ifi.p17.model.Model;

import java.awt.CardLayout;

import javax.swing.JPanel;

public class MainView extends JPanel{
	public static final String DETAIL_VIEW = "detail view";
	public static final String LIST_VIEW = "list view";
	
	private ViewAddNewPerson viewDetail;
	private ViewListPerson viewList;
	
	private CardLayout cardlayout = new CardLayout();  
	public MainView(Control control){
		this.setLayout(cardlayout);
        Model model = new Model();
        viewDetail = new ViewAddNewPerson(model);
        //viewList = new ViewListPerson(model);
        viewList = new ViewListPerson(control);
        
        viewDetail.setController(control);
        //viewList.setController(control);
        
        this.add(viewDetail, DETAIL_VIEW);
        this.add(viewList, LIST_VIEW);
        this.changeView(LIST_VIEW);
	}
	
	public void changeView(String key) {
		if(key.equals(LIST_VIEW)){
			viewList.revalidate();			
			viewList.repaint();
			viewList.tableRepaint();
		}
		cardlayout.show(this, key);
	}
    public void changeToDetailAndClear(){
    	this.changeView(DETAIL_VIEW);
    	viewDetail.clear();
    }
    public ViewListPerson getViewListPerson(){
    	return viewList;
    }
}
